import React, { useState } from 'react';
import { Button, Dropdown } from 'antd';
import { DownloadOutlined, FilePdfOutlined, FileTextOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { ExportPanel } from './ExportPanel';

interface ExportButtonProps {
  content: string;
  disabled?: boolean;
  onExportComplete?: (filename: string, format: string) => void;
}

export const ExportButton: React.FC<ExportButtonProps> = ({
  content,
  disabled = false,
  onExportComplete
}) => {
  const [showExportPanel, setShowExportPanel] = useState(false);

  const handleQuickExport = (_format: 'pdf' | 'word') => {
    // 快速导出，使用默认设置
    setShowExportPanel(true);
    // 这里可以在ExportPanel中添加初始tab设置
  };

  const menuItems: MenuProps['items'] = [
    {
      key: 'export-panel',
      label: '导出设置',
      icon: <DownloadOutlined />,
      onClick: () => setShowExportPanel(true)
    },
    {
      type: 'divider'
    },
    {
      key: 'quick-pdf',
      label: '快速导出PDF',
      icon: <FilePdfOutlined />,
      onClick: () => handleQuickExport('pdf')
    },
    {
      key: 'quick-word',
      label: '快速导出Word',
      icon: <FileTextOutlined />,
      onClick: () => handleQuickExport('word')
    }
  ];

  return (
    <>
      <Dropdown 
        menu={{ items: menuItems }} 
        placement="bottomRight"
        disabled={disabled || !content.trim()}
      >
        <Button 
          icon={<DownloadOutlined />}
          disabled={disabled || !content.trim()}
          title={!content.trim() ? '文档内容为空，无法导出' : '导出文档'}
        >
          导出
        </Button>
      </Dropdown>

      <ExportPanel
        visible={showExportPanel}
        content={content}
        onClose={() => setShowExportPanel(false)}
        onExportComplete={onExportComplete}
      />
    </>
  );
};